<template>
	<view class="page_box">
		<u-navbar :is-back="true" title="提现" v-if="1" :border-bottom="false" title-color="#000" back-icon-color="#000"></u-navbar>

		<view class="content_box padding ">
			<view class="padding-lg bg-white flex flex-direction r15">
				<text class="f32 text-black text-bold">可提现金额：{{ data.balance }}</text>
				<view class="solid-bottom flex justify-between mt50 padding-sm-tb">
					<input type="number" v-model="pay_money" value="" placeholder="请输入提现金额" placeholder-class="ddd" />
					<text class="text-red f28" @click="withdrawAll">全部提现</text>
				</view>
			</view>

			<view
				class="ww100 r10 margin-tb flex justify-start align-center h70 align-center padding-lr"
				style="background-color: #FFF5F5; color:#F2736D ;"
			>
				<i class="cuIcon-notice"></i>
				<text class="w2 h22  margin-lr-xs bg  "></text>
				<text>提现金额会在2个工作日内到账</text>
			</view>
			<view class="margin-tb flex align-center ">
				<image src="../../static/zhifb.png" mode="aspectFill" class="w44 h44 round"></image>
				<text class="f32 text-bold text-black ml15">支付宝提现</text>
			</view>
			<view class="padding bg-white r15">
				<view class="padding-tb-xs flex flex-direction solid-bottom">
					<text class="f28 text-black">账号</text>
					<input type="text" value="" v-model="user_account" placeholder="请输入支付宝账号" class="mt30" placeholder-class="ddd" />
				</view>
				<view class="pt40 flex flex-direction solid-bottom">
					<text class="f28 text-black">姓名</text>
					<input type="text" value="" v-model="user_real_name" placeholder="请输入支付宝姓名" class="mt30" placeholder-class="ddd" />
				</view>
			</view>
			<view class="flex justify-center mt88">
				<button class="cu-btn btn flex align-center justify-center  text-white w480 h100 r50 f30" @click="usrWdrl">
					<text>立即提现</text>
				</button>
				
				
				
			</view>
		</view>
		<yy-login v-if="vuex_login"></yy-login>
		<!-- 加载提示 -->
		<yy-loading text="加载中.." mask="true" click="true" ref="loading"></yy-loading>
		<!-- 信息提示-->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			user_account: '',
			user_real_name: '',
			pay_money: '',
			availableCshAmt: '',
			data: {},
			id: '',
		};
	},
	onShow() {},
	onLoad(e) {
		this.intfcDisp();
		this.preventDuplication();
	},
	methods: {
		// 获取金额
		async intfcDisp() {
			let obj = {};
			const res = await this.$u.post('/Finance/getBalance', obj);
			this.data = res.data;
			console.log('res >>  ', res);
		},
		//用户提现生成提现系列号接口，防止重复提交
		async preventDuplication() {
			let obj = {};
			const res = await this.$u.post('/Finance/generateWithdraw', obj);
			this.id = res.data.id;
			console.log('res >>  ', res);
		},
		// 全部提现
		async withdrawAll() {
			// this.pay_money = this.data.low_price;
			this.pay_money = this.data.balance;
		},
		async usrWdrl() {
			if ([this.pay_money, this.user_account, this.user_real_name].includes('')) {
				return this.$refs.uToast.show({ title: '请填写完整之后再提交', type: 'error' });
			}
			if (Number(this.pay_money) < Number(this.data.low_price)) {
				return this.$refs.uToast.show({ title: '不满足提现的最低金额', type: 'error' });
			}
			let obj = {
				id: this.id,
				user_account: this.user_account,
				user_real_name: this.user_real_name,
				pay_money: this.pay_money,
			};
			const res = await this.$u.post('Finance/withdraw', obj);

			if (res.code == 1) {
				this.$refs.uToast.show({ title: '提现金额会在2个工作日内到账', type: 'success' });
				this.intfcDisp();
				this.preventDuplication();
				this.pay_money='';
				this.user_account='';
				this.user_real_name='';
				

			} else {
				return this.$refs.uToast.show({ title: res.msg, type: 'error' });
			}
		},
	},
};
</script>

<style lang="scss" scoped>
.page_box {
	height: 100vh;
	background-color: #f7f7f7;
	.head_box {
	}
	.content_box {
		/deep/ .ddd {
			font-size: 28rpx;
			font-family: PingFang SC;
			// font-weight: 500;
			color: #999999;
		}
		/deep/input {
			font-size: 28rpx;
			font-family: PingFang SC;
			// font-weight: 500;
			color: #000;
		}
		.bg {
			background-color: #f2736d;
		}
	}
	.btn {
		background-color: #f2736d;
	}
}
</style>
